package cn.ycq.im.chat.clients;

import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
import io.netty.util.concurrent.GlobalEventExecutor;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author yuchaoqun
 * @email chaoqunyu9311@163.com
 * @date 2021.03.07 14:23
 */
public class ChannelAttributeUtils {

    public static Object getAttribute(String attrName, Channel channel) {
        AttributeKey<Object> attributeKey = AttributeKey.valueOf(attrName);
        Attribute<Object> attribute = channel.attr(attributeKey);
        return attribute == null ? null : attribute.get();
    }

    public static void setAttribute(String attrName, Channel channel,Object value) {
        AttributeKey<Object> attributeKey = AttributeKey.valueOf(attrName);
        Attribute<Object> attribute = channel.attr(attributeKey);
        Object old = attribute.get();
        attribute.compareAndSet(old,value);
    }
}
